<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Knowledge extends Model
{
    protected $table = 'knowledges';
    
    protected $fillable = [
        'category_id', 'title', 'type', 'file_url', 
        'third_party_link', 'status','is_wps','code', 'teacher_id', 'remark'
    ];

    // 转换file_url为数组（存储为JSON，查询时自动转为数组）
    protected $casts = [
        'file_url' => 'array',
    ];

    // 关联分类
    public function category()
    {
        return $this->belongsTo(KnowledgeCategory::class, 'category_id');
    }

    // 关联课程（多对多）
    public function courses()
    {
        return $this->belongsToMany(Course::class, 'course_knowledges');
    }
}